package com.ocm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ocm.core.mapping.DTOConfiguration;
import com.ocm.core.mapping.IDMapping;
import com.ocm.core.service.StorageService;

@Controller
public class OCMController {

   public static final String MAIN_PAGE = "ocm";

   public static final String LOGIN_PAGE = "login";

   private StorageService storageService;

   @Autowired
   public OCMController(
         @Qualifier("storageService") StorageService storageService) {
      this.storageService = storageService;
   }

   @RequestMapping(value = "/auth", method = RequestMethod.GET)
   public String viewMainPage(ModelMap model) {
      model.addAttribute("storages", this.storageService.findAll(DTOConfiguration.instance(IDMapping.STORAGE_LIMIT)));
      return MAIN_PAGE;
   }

   @RequestMapping(value = "/login", method = RequestMethod.GET)
   public String login(ModelMap model) {
      return LOGIN_PAGE;
   }
}
